package com.lyj.action;

import java.lang.reflect.ParameterizedType;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.interceptor.ApplicationAware;
import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.lyj.service.AdminService;
import com.lyj.service.MessageService;
import com.lyj.service.OptionService;
import com.lyj.service.QuestionService;
import com.lyj.service.QuestionnaireService;
import com.lyj.service.RecordService;
import com.lyj.service.UserService;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

/**
* 
* @author 李艺江
* @version 创建时间：2019年5月6日 下午10:51:14
*/

@Controller("baseAction")
@Scope("prototype")
public class BaseAction<T> extends ActionSupport implements RequestAware,SessionAware,ApplicationAware,ModelDriven<T>{

	private static final long serialVersionUID = 1L;
	
	protected Map<String, Object> request;
	protected Map<String, Object> session;
	protected Map<String, Object> application;
	
	protected T model;
	
	@Resource
	protected UserService userService;
	
	@Resource
	protected AdminService adminService;
	
	@Resource
	protected QuestionnaireService questionnaireService;
	
	@Resource
	protected MessageService messageService;
	
	@Resource
	protected OptionService optionService;
	
	@Resource
	protected QuestionService questionService;
	
	@Resource
	protected RecordService recordService;

	@Override
	public void setApplication(Map<String, Object> application) {
		this.application = application;
	}

	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	@Override
	public void setRequest(Map<String, Object> request) {
		this.request = request;
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	public T getModel() {
		ParameterizedType type = (ParameterizedType)this.getClass().getGenericSuperclass();
		Class clazz = (Class)type.getActualTypeArguments()[0];
		try {
			model = (T)clazz.newInstance();
		}catch (Exception e) {
			throw new RuntimeException(e);
		}
		return model;
	}

}
